import config from 'config';
import httpFetch from 'share/httpFetch';
import errorMessage from 'share/errorMessage';
export default {

  //获取 每个报表 的 字段属性 以及 关系查询   先写死 reportId=13  (效率审批明细表)  basicInfoReportIds=139,140 (基础信息表id列表，当前为固定值139,140)
  getLinkableData(){
    let params = {
      reportId: '13',
      basicInfoReportIds: '139,140'
    }
    return new Promise((resolve, reject) => {
      httpFetch.get(`${config.baseUrl}/report/api/report/column/mapping/relation`, params)
        .then((res) => {
          res.data.forEach((category)=>{
            let { reportColumnDTOList, reportColumnCustomizedDTOList } = category.masterReport;
            if (reportColumnCustomizedDTOList && reportColumnCustomizedDTOList.length !== 0) {
              reportColumnCustomizedDTOList.forEach((item)=>{
                item.label = item.columnDisplayName;
                item.value = item.id;
                item.targetReportId = category.basicInfoReport.id;
              })
            } else {
              reportColumnDTOList.forEach((item)=>{
                item.label = item.columnDisplayName;
                item.value = item.id;
                item.targetReportId = category.basicInfoReport.id;
              })
            }
          })
          resolve(res);
        })
        .catch(err => {
          errorMessage(err.response);
          reject(err)
          throw err;
        })
    })
  },

  //  新建/更新  导出设置
  newOrUpdateExportSetting(params) {
    return httpFetch.post(`${config.baseUrl}/report/api/report/column/export/setting`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  },

  //  获取导出设置 详情
  getExportSettingDetail(id) {
    return httpFetch.get(`${config.baseUrl}/report/api/report/column/export/setting/detail/${id}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  },

  // 删除单个设置
  deleteSingleExportSetting(id) {
    return httpFetch.delete(`${config.baseUrl}/report/api/report/column/export/setting/${id}`)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  },

  //  获取所有导出设置 list
  getAllSettings(params = { reportId: 13 }) {
    return httpFetch.get(`${config.baseUrl}/report/api/report/column/export/setting/list`, params)
      .catch(err => {
        errorMessage(err.response);
        throw err;
      })
  }
}
